﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace SurvivalStrategy.Console
{
    public  class ConsoleBox
    {    
        private Vector2 mPosition;
        private List<string> mText;
        private bool mIsVisable;
        DateTime mTime;

        public ConsoleBox(Game game, Vector2 position)
        {
            mText = new List<string>();
            this.mPosition = position;
            mIsVisable = false;
        }

        public void Update(GameTime gameTime)
        {
            if (mIsVisable)
            {
                int tSec = mTime.Second;
                int cSec = DateTime.Now.Second;
                if (cSec < tSec)
                    tSec = (60 - tSec);
                if (Math.Abs(cSec - tSec) > 5)
                {
                    Hide();
                }
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, SpriteFont spriteFont)
        {
            if (mIsVisable)
            {

                for (int i = 0; i < mText.Count; ++i)
                {
                    int currentY = (int)mPosition.Y - (i + 2) * 30;
                    spriteBatch.DrawString(spriteFont, mText[mText.Count - 1 - i], new Vector2(10, currentY), Color.White);
                }
            }
        }

        private void Show()
        {
            mIsVisable = true;
        }

        private void Hide()
        {
            mIsVisable = false;
        }

        public void AddText(string s)
        {
            mText.Add(s);
            if (mText.Count > 7)
            {
                mText.RemoveAt(0);
            }
            if (!mIsVisable)
            {
                Show();
                mTime = DateTime.Now;
            }
        }


    }
}

